<?php

/** 
 * @author felipe
 * 
 * 
 */
class App_Model_Db_Usuario extends Voitech_Db{
	protected $_name = 'usuario';
	protected $_primary = 'co_pessoa';
	
	static private $instancia;

	/**
	 * @return App_Model_Db_Usuario
	 */
	static public function build() {
		if( !isset( self::$instancia ) ) {
			$classe = __CLASS__;
			self::$instancia = new $classe();
		}
		return self::$instancia;
	}
        
        public function buscarPorId($id){
            $obSelect = $this->select()->where('co_pessoa = '.$id);
            return $this->getAdapter()->fetchRow($obSelect);            
        }
        
        public function listarTodos(Voitech_TO $obTO){
            $obSelect = $this->select();
            
            if(isset($obTO->co_pessoa) and !empty($obTO->co_pessoa)){
                $obSelect->where("co_pessoa =?",$obTO->co_pessoa);
            }
            if(isset($obTO->st_ativo) and !empty($obTO->st_ativo)){
                $obSelect->where("st_ativo =?",$obTO->st_ativo);
            }
            if(isset($obTO->order) and !empty($obTO->order)){
                $obSelect->order($obTO->order);
            }
            if(isset($obTO->limite) and !empty($obTO->limite)){
                $obSelect->limit($obTO->limite);
            }
            return $this->getAdapter()->fetchAll($obSelect);
        }
}